Skip to content

fix(ci): pytest 'import file mismatch' collection errors on test branch#993

Merged
aix-ahmet merged 1 commit into
developmentfrom
fix/pytest-import-file-mismatch
Jul 21, 2026
Merged

fix(ci): pytest 'import file mismatch' collection errors on test branch#993
aix-ahmet merged 1 commit into
developmentfrom
fix/pytest-import-file-mismatch

Conversation

@aix-ahmet

Copy link
Copy Markdown
Collaborator

CI on the test branch (and any branch running the full suite) aborts collection with 6 import file mismatch errors:

imported module 'test_model' has this __file__ attribute:
  .../tests/functional/v2/test_model.py
which is not the same as the test file we want to collect:
  .../tests/unit/v2/test_model.py

Root cause: duplicate test basenames (test_model.py, test_tool.py, test_session.py, test_trigger.py, test_api_key.py, test_rlm.py) across tests/unit/v2, tests/functional/v2, and tests/functional/model. Most test dirs have no __init__.py, so pytest's default prepend import mode assigns both files the same top-level module name and aborts.

Fix: addopts = --import-mode=importlib in pytest.ini — each test file gets a fully-qualified module name, so unique basenames are no longer required. This is pytest's recommended mode for new projects.

Verification:

  • pytest --collect-only: 1808 tests collected, 0 errors (was 1458 + 6 errors, collection interrupted)
  • pytest tests/unit: 1388 passed, 4 skipped
  • No test module imports another test module by bare name (the one pattern importlib mode would break)

🤖 Generated with Claude Code

https://claude.ai/code/session_018dCb6BE5bqjCrmsiPDGLRr

…collisions

Duplicate test basenames (test_model.py, test_tool.py, test_session.py,
test_trigger.py, test_api_key.py, test_rlm.py) exist in both tests/unit/v2
and tests/functional/v2 (and tests/functional/model). Without __init__.py
files, pytest's default prepend import mode maps them to the same module
name and aborts collection with 'import file mismatch'.

--import-mode=importlib gives each file a fully-qualified module name, so
unique basenames are no longer required.
@aix-ahmet
aix-ahmet merged commit 21b3d2c into development Jul 21, 2026
1 check passed
@aix-ahmet aix-ahmet mentioned this pull request Jul 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant